home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Macintosh Memory / MasterPointer.h < prev    next >
Text File  |  2000-06-23  |  3KB  |  85 lines

  1. // MasterPointer.h
  2.  
  3. #ifndef MasterPointer_h
  4. #define MasterPointer_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9. #ifndef Assert_h
  10. #include "Assert.h"
  11. #endif
  12. #ifndef Data_h
  13. #include "Data.h"
  14. #endif
  15.  
  16. #include <Memory.h>
  17.  
  18. class MasterPointer
  19.   {
  20.     private:
  21.         void *pointer;
  22.         
  23.         // These don't exist
  24.             MasterPointer( const MasterPointer& );
  25.             void operator=( const MasterPointer& );
  26.         
  27.         static void ThrowAllocationError( OSErr, void * );
  28.     
  29.     protected:
  30.         MasterPointer()        {}
  31.     
  32.     public:
  33.         enum SystemHeap { systemHeap };
  34.         enum Temporary { temporary };
  35.         
  36.         static MasterPointer& MakeEmpty()                                        { return *new MasterPointer; }
  37.         static MasterPointer& Make( uint32 size )                                { return *new( size ) MasterPointer; }
  38.         static MasterPointer& MakeEmptyInSystemHeap()                        { return *new( systemHeap ) MasterPointer; }
  39.         static MasterPointer& MakeInSystemHeap( uint32 size )                { return *new( size, systemHeap ) MasterPointer; }
  40.         static MasterPointer& MakeTemporary( uint32 size )                    { return *new( size, temporary ) MasterPointer; }
  41.         
  42.         void *operator new( size_t pointerSize );
  43.         void *operator new( size_t pointerSize, uint32 blockSize );
  44.         void *operator new( size_t pointerSize, SystemHeap );
  45.         void *operator new( size_t pointerSize, uint32 blockSize, SystemHeap );
  46.         void *operator new( size_t pointerSize, uint32 blockSize, Temporary );
  47.         void operator delete( void * );
  48.         
  49.         void *Pointer() const        { return pointer; }
  50.         ::Ptr Ptr() const                { return static_cast< ::Ptr>( pointer ); }
  51.         ::Handle Handle() const        { return reinterpret_cast< ::Handle>( const_cast<void **>(&pointer) ); }
  52.         
  53.         bool IsEmpty() const                        { return pointer == 0; }
  54.         void BeEmpty()                                { EmptyHandle( Handle() ); }
  55.         void Allocate( uint32 size )            { Assert( IsEmpty() ); ReallocateHandle( Handle(), int32(size) ); }
  56.         
  57.         uint32 Size() const                        { Assert( !IsEmpty() ); return uint32( GetHandleSize( Handle() ) ); }
  58.         void SetSize( uint32 newSize )        { Assert( !IsEmpty() ); SetHandleSize( Handle(), int32(newSize) ); }
  59.         
  60.         ::Data Data() const                        { return ::Data( Pointer(), Size() ); }
  61.         ::Data operator*() const                { return ::Data( Pointer(), Size() ); }
  62.         
  63.         SignedByte State() const                { return HGetState( Handle() ); }
  64.         void SetState( SignedByte state )    { HSetState( Handle(), state ); }
  65.         
  66.         void Lock()                                    { HLock( Handle() ); }
  67.         void Unlock()                                { HUnlock( Handle() ); }
  68.         
  69.         void AllowPurging()                        { HPurge( Handle() ); }
  70.         void ForbidPurging()                        { HNoPurge( Handle() ); }
  71.         
  72.         void BeResource()                            { HSetRBit( Handle() ); }
  73.         void BeNotResource()                        { HClrRBit( Handle() ); }
  74.         
  75.         static MasterPointer& At( ::Handle h )                    { return *reinterpret_cast<MasterPointer *>( h ); }
  76.         static MasterPointer& MasterPointerFor( void *p )    { return At( RecoverHandle( static_cast< ::Ptr>(p) ) ); }
  77.         
  78.         void MoveHigh()                            { MoveHHi( Handle() ); }
  79.         void LockHigh()                            { HLockHi( Handle() ); }
  80.         
  81.         THz Zone() const                            { return HandleZone( Handle() ); }
  82.   };
  83.  
  84. #endif
  85.